#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include <stdio.h>
#include <stdlib.h>

#define N 128

typedef struct msg
{
    long msg_type;
    char msg_text[N];
}MSG;

#define MSGTEXT_SIZE (sizeof(MSG)-sizeof(long))

int main()
{
    key_t mykey = 0;
    if((mykey = ftok(".",100)) == -1)
    {
        perror("fail to ftok");
        exit(-1);
    }

    int ms = 0;
    if((ms = msgget(mykey,IPC_CREAT| 0666)) == -1)
    {
        perror("fail to msgget");
        exit(-1);
    }
    
    MSG msg_1;
    MSG msg_2;
    if(msgrcv(ms,&msg_1,MSGTEXT_SIZE,0,0) == -1)
    {
        perror("fail to msgrcv");
        exit(-1);
    }
    printf("text = %s\n",msg_1.msg_text);
    if(msgrcv(ms,&msg_2,MSGTEXT_SIZE,0,0) == -1)
    {
        perror("fail to msgrcv");
        exit(-1);
    }
    printf("text = %s\n",msg_2.msg_text);
    system("ipcs -q");
    return 0;
}